We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.
Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)
$ (cd ~/proj/nasm/; git describe) nasm-2.15.05-118-g5368e457 $ newnasm -v NASM version 2.16rc0 compiled on Mar 24 2021 $ cat test2.asm %idefine words(b) ((b)+1>>1) %idefine fromwords(w) ((w)<<1) LOADCMDLINE_size equ 256 %assign ll fromwords(words(LOADCMDLINE_size)) %assign mm LOADCMDLINE_size %assign nn (words(LOADCMDLINE_size)) %assign oo fromwords(nn) dw ll ; expected 0100h dw mm ; expected 0100h dw nn ; expected 0080h dw oo ; expected 0100h $ newnasm test2.asm -l /dev/stderr 1 2 %idefine words(b) ((b)+1>>1) 3 %idefine fromwords(w) ((w)<<1) 4 5 LOADCMDLINE_size equ 256 6 %assign ll fromwords(words(LOADCMDLINE_size)) 7 %assign mm LOADCMDLINE_size 8 %assign nn (words(LOADCMDLINE_size)) 9 %assign oo fromwords(nn) 10 11 00000000 4000 dw ll ; expected 0100h 12 00000002 0001 dw mm ; expected 0100h 13 00000004 8000 dw nn ; expected 0080h 14 00000006 4000 dw oo ; expected 0100h $
equ appears to work as expected.
Same test case except using equ, which works fine: $ perl -pe 's/^\%assign\s+(\S+)\s+/$1 equ /' test2.asm > test3.asm $ cat test3.asm %idefine words(b) ((b)+1>>1) %idefine fromwords(w) ((w)<<1) LOADCMDLINE_size equ 256 ll equ fromwords(words(LOADCMDLINE_size)) mm equ LOADCMDLINE_size nn equ (words(LOADCMDLINE_size)) oo equ fromwords(nn) dw ll ; expected 0100h dw mm ; expected 0100h dw nn ; expected 0080h dw oo ; expected 0100h $ newnasm test3.asm -l /dev/stderr 1 2 %idefine words(b) ((b)+1>>1) 3 %idefine fromwords(w) ((w)<<1) 4 5 LOADCMDLINE_size equ 256 6 ll equ fromwords(words(LOADCMDLINE_size)) 7 mm equ LOADCMDLINE_size 8 nn equ (words(LOADCMDLINE_size)) 9 oo equ fromwords(nn) 10 11 00000000 0001 dw ll ; expected 0100h 12 00000002 0001 dw mm ; expected 0100h 13 00000004 8000 dw nn ; expected 0080h 14 00000006 0001 dw oo ; expected 0100h $
I suspect << and >> are mistokenizer in the preprocessor.
https://github.com/netwide-assembler/nasm/blob/5368e4579403daaf6c12165eb857893f8acfc7f8/asm/preproc.c#L1613 This is the culprit. It should set TOKEN_SHL but says TOKEN_SHR.
With this patch NASM appears to work. Building lDDebug symbolic results in exactly the same binary as with NASM version 2.15.03 which I used until now. nasm$ git diff diff --git a/asm/preproc.c b/asm/preproc.c index d1b9b31b..cb1669da 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -1613,7 +1613,7 @@ static Token *tokenize(const char *line) case '<': if (*p == '<') { p++; - type = TOKEN_SHR; + type = TOKEN_SHL; if (*p == '<') p++; } else if (*p == '=') { nasm$
I checked out the commit that contained this error. I didn't see any other obvious error. It's at https://github.com/netwide-assembler/nasm/commit/20e0d616dc954d567c8bf2c7e11cc5d6c10ac544
Oleg Oshmyan apparently fixed this 5 months ago so why is it not closed? I'm closing this now.